<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加信息</title>
    <link rel="stylesheet" href="${bp}/static/css/base.css">
    <script src="${bp}/static/js/jquery-1.11.1.js"></script>
    <style type="text/css">

        .inp{
            margin-top: 10px;
            width: 300px;
            height: 50px;
        }

    </style>
</head>
<body>
<%--使用jsp的指令引入公共头部--%>
<%@include file="header.jsp"%>

<div id="register">
    <h3>添加用户信息</h3>
    <form action="${bp}/user?method=add" method="post">
        <p><input type="text" name="username" class="inp" required placeholder="请输入用户名"> <span id="msg"></span></p>
        <p><input type="password" name="password" class="inp"  required placeholder="请输入密码"></p>
        <p><input type="text" name="tel" class="inp"  required placeholder="请输入联系方式"></p>
        <p><input type="text" name="address" class="inp"  required placeholder="请输入地址"></p>
        <p><input type="date" name="birth" class="inp" required></p>
        <p><input type="submit" value="添加" class="inp"></p>
    </form>
</div>
<span style="color: red">${requestScope.info}</span>
<script>
    $(":text").eq(0).blur(function () {
        let username =  $(this).val()
        console.log(username)
        // 发送ajax请求
        $.get("${bp}/user?method=checkUserName",{username:username},function (res) {
            if(res.code==200){
                $("#msg").css("color","green")
                $(":submit").attr("disabled",false)
            }else {
                $("#msg").css("color","red")
                $(":submit").attr("disabled",true)
            }
            $("#msg").text(res.msg)
        },'JSON')

    })

</script>
</body>
</html>
